package com.andromouse;

import java.awt.AWTException;
import java.awt.Robot;

public class MediaController {
	public boolean isWin;
	public static final int PLAY = 0;
	public static final int BACK = 1;
	public static final int NEXT = 2;
	public static final int STOP = 3;
	public static final int MUTE = 4;
	public static final int VOLUMEUP = 5;
	public static final int VOLUMEDOWN = 6;
	public static final int SUFFLE = 7;
	public static final int REPEAT = 8;
	public static final int FULLSCREEN = 9;
	public static final int LED = 10;
	public static final int CLOSE = 11;

	public void doMediaControl(int commandControlCode) throws AWTException {
		Robot r = new Robot();
		String operatingSystem = System.getProperty("os.name");
		if (operatingSystem.contains("Win")) {
			this.isWin = true;
		}
		switch (commandControlCode) {
		case 0:
			if (this.isWin) {
				r.keyPress(17);
				r.keyPress(80);
				r.keyRelease(17);
				r.keyRelease(80);
			} else {
				r.keyPress(32);
				r.keyRelease(32);
			}
			break;
		case 1:
			if (this.isWin) {
				r.keyPress(17);
				r.keyPress(66);
				r.keyRelease(17);
				r.keyRelease(66);
			} else {
				r.keyPress(157);
				r.keyPress(37);
				r.keyRelease(157);
				r.keyRelease(37);
			}
			break;
		case 2:
			if (this.isWin) {
				r.keyPress(17);
				r.keyPress(70);
				r.keyRelease(17);
				r.keyRelease(70);
			} else {
				r.keyPress(157);
				r.keyPress(39);
				r.keyRelease(157);
				r.keyRelease(39);
			}
			break;
		case 3:
			if (this.isWin) {
				r.keyPress(17);
				r.keyPress(83);
				r.keyRelease(17);
				r.keyRelease(83);
			} else {
				r.keyPress(32);
				r.keyRelease(32);
			}
			break;
		case 4:
			if (this.isWin) {
				r.keyPress(118);
				r.keyRelease(118);
			} else {
				r.keyPress(157);
				r.keyPress(18);
				r.keyPress(40);
				r.keyRelease(157);
				r.keyRelease(18);
				r.keyRelease(40);
			}
			break;
		case 5:
			if (this.isWin) {
				r.keyPress(120);
				r.keyRelease(120);
			} else {
				r.keyPress(157);
				r.keyPress(38);
				r.keyRelease(157);
				r.keyRelease(38);
			}
			break;
		case 6:
			if (this.isWin) {
				r.keyPress(119);
				r.keyRelease(119);
			} else {
				r.keyPress(157);
				r.keyPress(40);
				r.keyRelease(157);
				r.keyRelease(40);
			}
			break;
		case 7:
			if (!this.isWin)
				break;
			r.keyPress(17);
			r.keyPress(72);
			r.keyRelease(17);
			r.keyRelease(72);

			break;
		case 8:
			if (!this.isWin)
				break;
			r.keyPress(17);
			r.keyPress(84);
			r.keyRelease(17);
			r.keyRelease(84);

			break;
		case 9:
			if (!this.isWin)
				break;
			r.keyPress(18);
			r.keyPress(10);
			r.keyRelease(18);
			r.keyRelease(10);

			break;
		case 10:
			break;
		case 11:
			if (!this.isWin)
				break;
			r.keyPress(18);
			r.keyPress(115);
			r.keyRelease(18);
			r.keyRelease(115);
		}
	}
}